<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>协作文档</title>
		<style type="text/css">
			html,body{margin: 0;padding: 0;overflow: hidden;height: 100%;}
		</style>
	</head>
	<body>
		<div id="App">
			<!-- <p class="desc" style="word-break: break-all;">{{wpsUrl}}</p> -->
			<div style="height: 100%;width: 100%;display: flex;justify-content: center;align-items: center;">数据加载中...</div>
		</div>
		<!-- uni 的 SDK -->
		<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
		<script type="text/javascript" src="../js/vue.js"></script>
		<script type="text/javascript" src="../js/global.js"></script>
		<script type="text/javascript" src="../js/wps/web-office-sdk-v1.1.2.umd.js"></script>
		<script type="text/javascript">
			document.addEventListener('UniAppJSBridgeReady', function() {
				//webview传参到html5网页
				let wpsUrl=decodeURIComponent(GLOBAL_getUrlParam('wpsUrl'))
				let token=GLOBAL_getUrlParam('token');
				console.log('wpsUrl',wpsUrl);
				let opData={
					wpsUrl,
					token
				}
				let that
				new Vue({
					el: '#App',
					data: {
						wpsUrl:opData.wpsUrl,
						token:opData.token,
						simpleMode:false,//
					},
					mounted() {
						that=this
						this.openWps(that.wpsUrl,that.token)
					},
					methods: {
						//打开wps
						openWps(url, token) {
							console.log("token", token);
							console.log("url", url);
						    const wps =WebOfficeSDK.config({
						        mode: that.simpleMode?'simple':'normal',//normal普通模式， 展示所有功能界面 simple极简模式， 不显示头部和工具栏	
						        // mount: document.querySelector('#app'),
						        wpsUrl:url,
						    });
							// 鉴权设置
						    wps.setToken({"token": token});
						    // let app = wps.Application;
						    // console.log(JSON.stringify(app))
							// 如果需要对iframe进行特殊的处理，可以通过以下方式拿到iframe的dom对象
							console.log(wps.iframe)
							// 打开文档结果
							wps.on('fileOpen', function(data) {
							    console.log('打开文档成功',data.success)
							})
							// 打开文档结果
							wps.on('error', function(error) {
							    console.log('打开文档失败',error)
							})
							//文件保存
							wps.on('fileSaved', function(data) {
								console.log('文档保存成功',data)
								uni.postMessage({
									data: {
										action: '文档保存成功'
									}
								});
							})
						},
					}
				})
			});
			
		</script>
	</body>
</html>
